package com.lzy.controller;

import java.util.Arrays;
import java.util.Map;

import com.lzy.service.ISysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.lzy.common.R;
import com.lzy.entity.SysDictTypeEntity;

/**
 * 字典类型表
 *
 * @author lyw
 * @email lyw@gmail.com
 * @date 2023-02-27 20:34:44
 */
@RestController
@RequestMapping("/sysdicttype")
public class SysDictTypeController {
    @Autowired
    private ISysDictTypeService sysDictTypeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions(".:sysdicttype:list")
    public R list(@RequestParam(value = "page", defaultValue = "1") Integer page,
                  @RequestParam(value = "limit", defaultValue = "10") Integer limit){
        Page<Map<String, Object>> result = new Page<>(page, limit);
        LambdaQueryWrapper<SysDictTypeEntity> lqw = new LambdaQueryWrapper<>();
        IPage<Map<String, Object>> list = sysDictTypeService.selectPageList(result, lqw);
        return R.ok().put("page", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{dictId}")
    // @RequiresPermissions(".:sysdicttype:info")
    public R info(@PathVariable("dictId") Long dictId){
		SysDictTypeEntity sysDictType = sysDictTypeService.getById(dictId);

        return R.ok().put("sysDictType", sysDictType);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions(".:sysdicttype:save")
    public R save(@RequestBody SysDictTypeEntity sysDictType){
		sysDictTypeService.save(sysDictType);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions(".:sysdicttype:update")
    public R update(@RequestBody SysDictTypeEntity sysDictType){
		sysDictTypeService.updateById(sysDictType);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    // @RequiresPermissions(".:sysdicttype:delete")
    public R delete(@RequestBody Long[] dictIds){
		sysDictTypeService.removeByIds(Arrays.asList(dictIds));

        return R.ok();
    }

}
